<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        canvas{border: 1px solid #aaa;}
    </style>
</head>
<body>
    <canvas width="600" height="400" class="myCanvas">
        当前的浏览器版本不支持，请升级浏览器
    </canvas>

    <script>
        /* 得到canvas的画布 */
        var canvas = document.getElementsByClassName('myCanvas')[0];

        /* 得到画布的上下文，有2D的上下文和3D的上下文 */
        //2D
        var ctx = canvas.getContext('2d');
        //绘制矩形
        ctx.fillStyle = 'red';  //先设置颜色
        ctx.fillRect(100,100,200,50);  //前两个是定位，后两个是宽高

    </script>
</body>
</html>
